home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
qtawk
/
calexpt.exp
< prev
next >
Wrap
Text File
|
1990-04-30
|
5KB
|
129 lines
# QTAwk program to print calender - 1770 to 2070 inclusive
# years changed by changing yr1 and yr2 variables
#
# (C) Copyright 1989, 1990 Terry D. Boldt, All Rights Reserved
#
#
BEGIN {
#
# print calenders with day of week header
#
printf("\t(C) Copyright 1989, 1990 Terry D. Boldt\n\tAll Rights Reserved\n");
printf("\t S M T W T F S\t S M T W T F S\t S M T W T F S\n");
printf("\t0 1 2 3 4 5 6 7\t1 1 2 3 4 5 6\t2 1 2 3 4 5\n");
printf("\t 8 9 10 11 12 13 14\t 7 8 9 10 11 12 13\t 6 7 8 9 10 11 12\n");
printf("\t 15 16 17 18 19 20 21\t 14 15 16 17 18 19 20\t 13 14 15 16 17 18 19\n");
printf("\t 22 23 24 25 26 27 28\t 21 22 23 24 25 26 27\t 20 21 22 23 24 25 26\n");
printf("\t 29 30 31 \t 28 29 30 31 \t 27 28 29 30 31\n");
printf("\t3 1 2 3 4\t4 1 2 3\t5 1 2\n");
printf("\t 5 6 7 8 9 10 11\t 4 5 6 7 8 9 10\t 3 4 5 6 7 8 9\n");
printf("\t 12 13 14 15 16 17 18\t 11 12 13 14 15 16 17\t 10 11 12 13 14 15 16\n");
printf("\t 19 20 21 22 23 24 25\t 18 19 20 21 22 23 24\t 17 18 19 20 21 22 23\n");
printf("\t 26 27 28 29 30 31 \t 25 26 27 28 29 30 31\t 24 25 26 27 28 29 30\n");
printf("\t \t \t 31\n");
printf("\t6 1\n");
printf("\t 2 3 4 5 6 7 8\n");
printf("\t 9 10 11 12 13 14 15\n");
printf("\t 16 17 18 19 20 21 22\n");
printf("\t 23 24 25 26 27 28 29\n");
printf("\t 30 31\n");
printf("\t 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │\n");
printf("\tJan (31d) F N │A J │B M │C G │D L │E H │I K │\n");
printf("\tFeb (28d) D L*│E* H │I K*│F N*│A J*│B M*│C G*│\n");
printf("\tMar (31d) D G │H L │E I │F K │A N │B J │C M │\n");
printf("\tApr (30d) A N │B J │C M │D G │H L │E I │F K │\n");
printf("\tMay (31d) E I │F K │A N │B J │C M │D G │H L │\n");
printf("\tJun (30d) C M │D G │H L │E I │F K │A N │B J │\n");
printf("\tJul (31d) A N │B J │C M │D G │H L │E I │F K │\n");
printf("\tAug (31d) H L │E I │F K │A N │B J │C M │D G │\n");
printf("\tSep (30d) B J │C M │D G │H L │E I │F K │A N │\n");
printf("\tOct (31d) F K │A N │B J │C M │D G │H L │E I │\n");
printf("\tNov (30d) D G │H L │E I │F K │A N │B J │C M │\n");
printf("\tDec (31d) B J │C M │D G │H L │E I │F K │A N │\n\n\n");
# define year patterns
m_indx[ 0] = "*144025036146";
m_indx[ 1] = "*255136140250";
m_indx[ 2] = "*366240251361";
m_indx[ 3] = "*400351362402";
m_indx[ 4] = "*512503514624*"; # leap year
m_indx[ 5] = "*033614625035";
m_indx[ 6] = "*360351362402*"; # leap year
m_indx[ 7] = "*511462403513";
m_indx[ 8] = "*622503514624";
m_indx[ 9] = "*145136140250*"; # leap year
m_indx[10] = "*623614625035*"; # leap year
m_indx[11] = "*401462403513*"; # leap year
m_indx[12] = "*256240251361*"; # leap year
m_indx[13] = "*034025036146*"; # leap year
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
stderr = "stderr";
#
# Gregorian/Julian calender flag.
# TRUE == julian
# FALSE == gregorian
#
greg_jul = FALSE;
yr_cnt = 0;
yr1 = 2080; # first year of range
yr2 = 2385; # second year of range
# 1770 to 2080 fits nicely on a single page
printf("\t 0 1 2 3 4 5 6 7 8 9\n");
for ( yr = yr1 ; yr <= yr2 ; ) {
myr = yr % 100;
if ( myr == 00 || myr == 50 ) printf("\t 0 1 2 3 4 5 6 7 8 9\n");
printf("\t%4u: ",yr);
for ( mm = 0 ; mm < 10 ; yr++ , mm++ ) {
#
# use jdn function to compute julian day number of first day of
# each month of year. Then compute week-day of first day of
# month Sunday == 0, Monday == 1 ... Saturday == 6
#
for ( i = 1 , yr_num = '*' ; i <= 12 ; i++ ) {
mn_num = (jdn(yr,i,1) + 1) % 7;
yr_num ∩= mn_num; # build pattern for year
}
# check for leap year
fdf = substr(yr_num,3,1);
fdm = substr(yr_num,4,1);
if ( fdf != fdm ) {
leap_yr = TRUE;
yr_num ∩= '*';
} else leap_yr = FALSE;
found = FALSE;
for ( i in m_indx )
# compare year pattern to matrix of patterns to find index
# into Alpha string designating year
if ( m_indx[i] == yr_num ) {
yr_num = i;
found = TRUE;
break;
}
# if year pattern wasn't found - error
if ( !found ) {
fprintf(stderr,"another matrix element");
exit;
}
# print element of decade - print '*' if leap year
printf("%c%c",substr(alpha,yr_num + 1,1),leap_yr ? '*' : ' ');
}
printf("\n");
}
}
# function to convert year/month/day into julian day number
function jdn(year,month,day) {
local yr;
local pfac = 0.6;
local ljdn;
yr = year + (month - 3.0) / 12.0;
ljdn = int(367.0 * yr + pfac) - (2 * int(yr)) + int(yr/4.0)
+ int(day) + 1721117;
if ( !greg_jul ) ljdn += -int(yr/100.0) + int(yr/400.0) + 2;
return ljdn;
}